#!/usr/bin/env bash

declare -r DOCKER_HUB="docker-hub:5000"
declare -r NACOS_HOME="/appdata/nacos"

sudo mkdir -p ${NACOS_HOME}/{conf,logs,data}

if [ "$1" == "0" ]; then
  docker run -d --name nacos \
  -p 8848:8848 -p 9848:9848 \
  -e MODE=standalone \
  -e SPRING_DATASOURCE_PLATFORM=mysql \
  -e MYSQL_SERVICE_HOST=192.168.176.33 \
  -e MYSQL_SERVICE_PORT=3306 \
  -e MYSQL_SERVICE_DB_NAME=nacos \
  -e MYSQL_SERVICE_USER=nacos \
  -e MYSQL_SERVICE_PASSWORD=nacos \
  ${DOCKER_HUB}/nacos/nacos-server:v2.1.1
else
  docker run -d --name nacos \
  --restart always \
  -p 8848:8848 -p 9848:9848 \
  -e MODE=standalone \
  -e SPRING_DATASOURCE_PLATFORM=mysql \
  -e MYSQL_SERVICE_HOST=192.168.176.33 \
  -e MYSQL_SERVICE_PORT=3306 \
  -e MYSQL_SERVICE_DB_NAME=nacos \
  -e MYSQL_SERVICE_USER=nacos \
  -e MYSQL_SERVICE_PASSWORD=nacos \
  -v ${NACOS_HOME}/conf:/home/nacos/conf \
  -v ${NACOS_HOME}/logs:/home/nacos/logs \
  -v ${NACOS_HOME}/data:/home/nacos/data \
  ${DOCKER_HUB}/nacos/nacos-server:v2.1.1
fi
